//
//  ZBMoBanFiveScrollview.m
//  MoBan
//
//  Created by apple on 16/7/12.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ZBMoBanFiveScrollview.h"
#import "ZBMoBanFiveTieamCell.h"
@interface ZBMoBanFiveScrollview()
@property(nonatomic,strong)NSMutableArray *array;
@end
@implementation ZBMoBanFiveScrollview
-(NSMutableArray *)array
{
    if (!_array) {
        _array = [NSMutableArray array];
    }
    return _array;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addUI];
    }
    return self;
}
-(void)addUI
{
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.array removeAllObjects];
    
    NSMutableArray *array =  [self.datasouce ZBDatasouceFromArray];
    
    for (NSInteger i=0; i<array.count; i++) {
        
        ZBMoBanFiveTieamCell *cell = [[ZBMoBanFiveTieamCell alloc]init];
        cell.tag = i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cellDidSelect:)];
        [cell addGestureRecognizer:tap];
        
        [self addSubview:cell];
        [self.array addObject:cell];
    }

    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    for (NSInteger i=0; i<self.array.count; i++) {
        ZBMoBanFiveTieamCell *cell = self.array[i];
        cell.frame = CGRectMake((KscrW/4)*i, 0, KscrW/4, self.height);
    }
    self.contentSize = CGSizeMake((KscrW/4)*self.array.count, self.height);
}
-(void)reloadDta
{
    [self addUI];
}
-(void)cellDidSelect:(UIGestureRecognizer *)tap
{
    if ([self.deleget respondsToSelector:@selector(ZBDidSelectde:)]) {
        [self.deleget ZBDidSelectde:tap.view.tag];
    }

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
